package com.yong.common.hibernate;

import java.util.ArrayList;
import java.util.List;

public class Paging<T> {

	private Integer pageSize;
	
	private Integer page;
	
	private Integer maxPage;
	
	private Integer start;
	
	private Integer total;
	
	private List<T> list;
	
	public Paging() {
		pageSize = 10;
		page = 1;
		maxPage = 0;
		start = 0;
		total = 0;
		list = new ArrayList<T>();
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		if (page != null)
			this.page = page;
	}
	
	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 重新计算页数，不必每次都要在服务端重新计算，自身逻辑  by y.nie
	 * @return
	 */
	public Integer getMaxPage() {
		if (maxPage == 0 && total > 0 && pageSize > 0) {
			maxPage = (total - 1) / pageSize + 1;
		}

		return maxPage;
	}

	public void setMaxPage(Integer maxPage) {
		this.maxPage = maxPage;
	}
	
	public Integer getStart() {
		if (page < 1)
			page = 1;
		this.start = (page - 1) * pageSize;
		return this.start;
	}
	
	public void setStart(Integer start) {
		this.start = start;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
	
}
